import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class test_systems {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/test_systems";
        String user = "root";
        String psw = "********";
        Connection conn= DriverManager.getConnection(url, user, psw);
        String sql = "insert into exams values (4,?,?)";//?是代表还未指定内容
        //update exams set total_score =40 where exam_id=1--更新
        //delete from exams where exam_id = 4--删除
        PreparedStatement psmt= conn.prepareStatement(sql);//创建预处理命令对象
        psmt.setString(1,"试卷四"); //填充内容参数
        psmt.setInt(2,30);
        int i= psmt.executeUpdate();
        System.out.println(i > 0 ?"添加成功":"添加失败");
        //7.释放资源(关闭连接，先关闭psmt，再关闭connection)
        psmt.close();
        conn.close();
    }
}



